<template>
  <div>
    <SearchForm
        @search="onSearch"
        @reset="onReset"
        :search-list="searchList" :search-params="searchParams">
    </SearchForm>

    <div class="table-layout">
      <el-card shadow="never">
        <div class="table-handle">
          <el-button type="primary" size="mini" icon="el-icon-plus" @click="onAdd">新增</el-button>
        </div>
        <div class="table-box">
          <el-table
              size="large"
              stripe
              border
              v-loading="loading"
              max-height="500px"
              :data="tableData"
              row-key="id"
              element-loading-spinner="el-icon-loading"
              element-loading-background="rgba(255, 255, 255, 0.8)"
              @selection-change="onSelect"
          >
            <el-table-column prop="title" label="线路名称" width="150"/>

            <el-table-column prop="price" label="价格" width="100">
              <template slot-scope="scope">
                {{ scope.row.price }}元
              </template>
            </el-table-column>
            <el-table-column prop="price" label="标签" width="300">
              <template slot-scope="scope">
                <el-tag style="margin: 4px" v-for="tag in (scope.row.tags || '').split(',')" :key="tag">{{tag}}</el-tag>
                <el-tag style="margin: 4px" v-for="tag in (scope.row.tags2 || '').split(',')" :key="tag">{{tag}}</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="price" label="团期" width="300">
              <template slot-scope="scope">
                <div style="margin: 2px 0" v-for="date in (scope.row.dates || '').split(',')" >{{ date }}</div>
              </template>
            </el-table-column>
            <el-table-column prop="original_price" label="原价" width="100">
              <template slot-scope="scope">
                {{ scope.row.original_price }}元
              </template>
            </el-table-column>
            <el-table-column prop="virtual_sale_count" label="虚拟销量" width="100"/>
            <el-table-column prop="sort" label="排序" width="80"/>
            <el-table-column prop="status" label="状态" width="100">
              <template slot-scope="scope">
                <el-tag v-if="scope.row.status === 1" type="success">正常</el-tag>
                <el-tag v-else type="info">禁用</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="操作" fixed="right" width="120">
              <template slot-scope="scope">
                <el-button type="text" @click="onEdit(scope.row)">编辑</el-button>
                <el-button style="color: #F82222" type="text" @click="onDelete(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-card>
      <div class="page-box">
        <el-pagination
            background
            :current-page="pageNo"
            :page-sizes="pageSizes"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalSize"
            @size-change="changePageSize"
            @current-change="changePageNo"
        />
      </div>
    </div>
    <Add ref="addFormRef" @get-page="initData" />
  </div>
</template>
<script>

import crud from "@/mixins/crud";
import { http } from "@/api";
import Add from "./add";

export default {
  name: "news",
  components: {
    Add
  },
  mixins: [crud],
  data() {
    return {
      request: {
        ...http.product,
      },
      searchList: [
        {
          label: '线路名称',
          prop: 'title',
          name: 'input',
          clearable: true
        },
        {
          label: '状态',
          prop: 'status',
          name: 'select',
          clearable: true,
          options: [
            { label: '正常', value: 1 },
            { label: '禁用', value: 0 }
          ]
        }
      ],
      searchParams: {
        title: '',
        status: '',
        type: 2
      },
      defaultParams: {
        type: 2
      },
      tableData: [],
    }
  },
  methods: {
    onEdit2(row) {
      this.$router.push({
        path: '/product/item/' + row.id
      })
    },
    onEdit3(row) {
      this.$router.push({
        path: '/product/buy/' + row.id
      })
    }
  }
}
</script>

<style scoped lang="scss">
.table-layout {
  margin-top: 20px;
}
.table-handle {
  margin-bottom: 20px;
}
.page-box {
  margin-top: 20px;
  text-align: right;
}
</style>
